package com.j2eefast.pm.controller;

import com.j2eefast.common.core.business.annotaion.BussinessLog;
import com.j2eefast.common.core.enums.BusinessType;
import com.j2eefast.common.core.utils.*;
import com.j2eefast.framework.annotation.RepeatSubmit;
import com.j2eefast.common.core.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.ui.ModelMap;
import java.util.Map;
import java.util.Date;
import org.springframework.web.bind.annotation.*;
import com.j2eefast.pm.entity.sysCompanyEntity;
import com.j2eefast.pm.service.sysCompanyService;

/**
 * 物业公司页面控制器
 * @author paradisehere
 * @date 2020-05-23 11:15
 */
@Controller
@RequestMapping("/company/company")
public class sysCompanyController extends BaseController{

    private String prefix = "modules/company/company";

    @Autowired
    private sysCompanyService sysCompanyService;

    @RequiresPermissions("company:company:view")
    @GetMapping()
    public String company(){
        return prefix + "/company";
    }

        
    @RequestMapping("/list")
    @RequiresPermissions("company:company:list")
    @ResponseBody
    public ResponseData list(@RequestParam Map<String, Object> params) {
		PageUtil page = sysCompanyService.findPage(params);
		return success(page);
    }
    

    
        

    @GetMapping("/add")
    public String add(){
        return prefix + "/add";
    }

    /**
     * 新增
     */
    @RepeatSubmit
    @RequiresPermissions("company:company:add")
    @BussinessLog(title = "物业公司", businessType = BusinessType.INSERT)
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData addsysCompany(@Validated sysCompanyEntity sysCompany){
        //校验参数
        ValidatorUtil.validateEntity(sysCompany);
        return sysCompanyService.savesysCompany(sysCompany)? success(): error("新增失败!");
    }
    
        /**
     * 修改
     */
    @RequiresPermissions("company:company:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap){
        sysCompanyEntity sysCompany = sysCompanyService.getsysCompanyById(id);
        mmap.put("sysCompany", sysCompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存物业公司
     */
    @RepeatSubmit
    @RequiresPermissions("company:company:edit")
    @BussinessLog(title = "物业公司", businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public ResponseData editsysCompany(sysCompanyEntity sysCompany){
		ValidatorUtil.validateEntity(sysCompany);
        return sysCompanyService.updatesysCompanyById(sysCompany)? success(): error("修改失败!");
    }
    
    
        /**
     * 删除
     */
    @RepeatSubmit
    @BussinessLog(title = "物业公司", businessType = BusinessType.DELETE)
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @RequiresPermissions("company:company:del")
    @ResponseBody
    public ResponseData del(Long[] ids) {
      return sysCompanyService.deletesysCompanyByIds(ids)? success(): error("删除失败!");
    }
    
}
